package com.enjoybyte.pangu.controller;

import com.enjoybyte.pangu.enums.ResultCode;
import com.enjoybyte.pangu.global.BizException;
import com.enjoybyte.pangu.util.Result;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/hello")
public class HelloController {

    @GetMapping("/world")
    public Result world(){
        log.info("hell world!");
        return Result.ok();
    }

    @GetMapping("/getData")
    public Result getData(HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        map.put("id",1);
        map.put("name","jack");
        map.put("age",33);
        List<Map<String,Object>> list = new ArrayList<>();
        list.add(map);
        Map<String,Object> map2 = new HashMap<>();
        map2.put("id",2);
        map2.put("name","rose");
        map2.put("age",23);
        list.add(map2);
        log.info("获取信息！{},请求地址：{}",list,request.getRequestURI());
        return Result.ok(list);
    }

    @GetMapping("/exception")
    public Result exception(){
        log.info("测试异常!");
        throw new BizException(ResultCode.ERROR);
    }
}
